package zuoye03;

import java.util.ArrayList;
import java.util.Random;

public class Manager {
    public String username;
    private int moeny;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public int getMoeny() {
        return moeny;
    }
    public void setMoeny(int moeny) {
        this.moeny = moeny;
    }
    public Manager(String username, int moeny) {
        this.username = username;
        this.moeny = moeny;
    }
    public Manager() {
    }

    public ArrayList<Integer> send(int totalMoeny,int count){
        ArrayList<Integer> redList=new ArrayList<Integer>();
        //群主得先看自己钱够不够
        int leftMoney=this.moeny;
        if(totalMoeny>leftMoney){
            System.out.println("余额不足");
            return redList;//返回null
        }
        //扣钱
        this.setMoeny(leftMoney-totalMoeny);
        //发红包 ，分成n等分
        int mod=totalMoeny%count;//余数 零头
       int avg=totalMoeny/count;
        //除开零头 先放一样得钱
        for(int i=count;i>0;i--){
            avg=totalMoeny/i;
            if(i==1){
redList.add(totalMoeny);
break;
            }
            Random r=new Random();
            int x=r.nextInt(2*avg)+1;
            redList.add(x);
            totalMoeny=totalMoeny-x;
        }
        //最后一个红包
        return redList;
    }
    public void show(){
        System.out.println("我叫:"+username+",我有多少钱:"+moeny);
    }
}
